/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.cacheplugins.ws  
 */
package com.apache.bid.service.cacheplugins.ws;

import java.util.List;
import java.util.Map;

import com.apache.api.manager.PluginConnector;
import com.apache.api.manager.ProxyManager;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.Constant;
import com.apache.bid.entity.BidSession;
import com.apache.cache.util.Validator;
import com.apache.database.constant.SystemTools;

/**
 * description:  同步活动信息
 * @author dyhou 创建时间：2016-6-6  
 */
public class BidSessionSynPluginImpl implements PluginConnector {

	private ProxyManager wbdProxyCacheManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		List<Map<String, String>> list = (List<Map<String, String>>) param.getParams("session");
		if (Validator.isEmpty(list)) {
			entity.setResult("false");
			entity.setMessage("活动信息为空");
			return entity;
		}
		Map<String, String> sessions = list.get(0);
		ParamsVo<BidSession> vo = new ParamsVo<BidSession>();
		BidSession session = getSessionInfo(sessions);
		vo.setParams("createUserId", sessions.get("createUid"));
		vo.setParams("createUserName", sessions.get("createUname"));
		vo.setParams("bjServer", SystemTools.getInstance().getValue("wbd_cache_url"));
		vo.setParams("bjPort", SystemTools.getInstance().getValue("wbd_cache_port"));
		vo.setParams("ztUrl", sessions.get("url"));//专厅图片
		//vo.setParams("infoDesc", sessions.get("url"));
		vo.setParams("bailPayMode", sessions.get("bailmode"));
		vo.setParams("just", sessions.get("justorg"));
		vo.setParams("ruleUrl", sessions.get("ruleUrl"));
		vo.setParams("noticeUrl", sessions.get("noticeUrl"));
		vo.setParams("noticeUrl", sessions.get("noticeUrl"));
		vo.setParams("fax", sessions.get("fax"));
		vo.setParams("email", sessions.get("email"));
		vo.setParams("tel", sessions.get("tel"));
		vo.setParams("bailCurrency", sessions.get("bailcurrency"));
		vo.setParams("rulemask", sessions.get("rulemask"));
		vo.setParams("agentOrg", sessions.get("agentOrg"));
		vo.setParams("address", sessions.get("address"));
		vo.setParams("isBroadCast", sessions.get("isbroadcast"));
		vo.setParams("isBroadCast", sessions.get("isbroadcast"));
		vo.setParams("bailPriceUnit", sessions.get("monunit"));
		vo.setParams("bailTimeStart", sessions.get("bailtimestart"));
		vo.setParams("bailTimeEnd", sessions.get("bailtimeend"));
		vo.setParams("bailTimeEnd", sessions.get("bailtimeend"));
		vo.setParams("bailTimeEnd", sessions.get("bailtimeend"));
		vo.setParams("chargeName", sessions.get("lkname"));
		vo.setObj(session);
		vo.setKey("cacheSaveSessionPlugin");
		entity = (ResultEntity) wbdProxyCacheManager.saveInvoke(vo);
		return entity;
	}

	private BidSession getSessionInfo(Map<String, String> sessions) {
		BidSession session = new BidSession();
		session.setSessionId(sessions.get("sessionid"));
		session.setOrgCname(sessions.get("organization"));
		session.setSessionName(sessions.get("sename"));
		session.setSessionNo(sessions.get("seno"));
		session.setSenature(sessions.get("senature"));
		session.setCreateTime(sessions.get("createtime"));
		session.setModifyTime(sessions.get("updatetime"));
		session.setStatus("2");
		session.setArea(sessions.get("area"));
		session.setCity(sessions.get("city"));
		session.setPicUrl(sessions.get("picurl"));
		session.setOrderNumber(sessions.get("orderNumber"));
		session.setAllowApply(sessions.get("allowApply"));
		if ("0".equals(sessions.get("sessType"))) {
			session.setSessionType(Constant.SETYPE_ZC);
		} else {
			session.setSessionType(sessions.get("sessType"));
		}
		session.setSessionMode(sessions.get("sessMode"));
		if ("T".equals(sessions.get("isbail"))) {
			session.setBailCtrl("1");//是否缴纳保证金，按固定金额收取
			session.setBailFix(sessions.get("bail"));//保证金金额
		} else if ("B".equals(sessions.get("isbail"))) {
			session.setBailCtrl("2");//是否缴纳保证金，按标的数量收取
			session.setBailFix(sessions.get("bail"));
		} else if ("C".equals(sessions.get("isbail"))) {
			session.setBailCtrl("3");//是否缴纳保证金，按标的起始价比例收取
			session.setBailMax(sessions.get("maxBail"));
			session.setBailRate(sessions.get("bailPercent"));
		} else {
			session.setBailCtrl("0");//不收保证金
		}
		session.setSessionLayout(sessions.get("hallLayout"));
		//session.setSessionCss(sessions.get("cssControl"));
		session.setExceptionStatus(sessions.get("exceptionStatus"));
		return session;
	}

	public void setWbdProxyCacheManager(ProxyManager wbdProxyCacheManager) {
		this.wbdProxyCacheManager = wbdProxyCacheManager;
	}

}
